// 引用mongoose模块
var mongoose = require('mongoose');
mongoose.Promise = global.Promise;
// 连接数据库
mongoose.connect('mongodb://localhost/book', {useMongoClient: true})
var db = mongoose.connection;
db.once('error', () => console.log('Mongo 连接失败!'));
db.once('open', () => console.log('mongodb 连接成功!'));

// 创建对象定义集合结构类型(其实就是表结构)
var testSchema = new mongoose.Schema({
  book_title: String,
  book_author: String,
  book_price: String,
  book_desc: String,
  book_img: String
});

// 列表
var BookList = mongoose.model('BookList', testSchema);

module.exports = BookList;
